lib = Dir('lib')
build = Dir('build')
src = Dir('src')
inc = Dir('include')

prefix = Dir(ARGUMENTS.get('prefix', '.'))
prefix_lib = prefix.Dir('lib')
prefix_inc = prefix.Dir('include')

lib_paths = [lib]
cpp_paths = [prefix_inc, inc]

ccflags = ['-Wall', '-Werror']
if 'debug' in COMMAND_LINE_TARGETS:
	ccflags += ['-g']

BuildDir(build, src, duplicate=0)

build_sources = [build.File('strxml.cpp')]

env = Environment(tools = ["default", "tools"], toolpath = '.',
                  CPPPATH=cpp_paths, CCFLAGS=ccflags, LIBPATH=lib_paths)
import os
shared_lib_suffix = ".so"
if os.uname()[0] == "Darwin":
	shared_lib_suffix = ".dylib"
	env.Append(SHLINKFLAGS='-undefined dynamic_lookup')

config = Configure(env)
config.CheckCXXHeader('boost/shared_ptr.hpp')
env = config.Finish()

libstrxml = env.SharedLibrary(lib.File('libstrxml'+shared_lib_suffix), build_sources)

Default(libstrxml)

Alias('debug', libstrxml)

if prefix != Dir('.'):
	Alias('install', env.InstallPerm(prefix_lib, libstrxml, 0644))
	Alias('install', env.InstallPerm(prefix_inc, inc.Entry('strxml.hpp'), 0644))

dist_files = [File(x) for x in """
COPYING COPYING.LESSER SConstruct tools.py
""".split()]
dist_files += [inc.Entry('strxml.hpp')]
dist_files += [src.Entry(build_source) for build_source in build_sources] 

env.Alias('dist', env.DistTar('strxml.tar.gz', dist_files))
